import Vue from 'vue'

Vue.directive('theme', {
  inserted(el, binding) {
    if (typeof window.theme !== 'undefined') {
      let style = ''
      for (const key in binding.value) {
        if (binding.value.hasOwnProperty(key)) {
          const target = binding.value[key]
          if (typeof window.theme[target] !== 'undefined') {
            style += key + ':' + window.theme[target] + ';\n'
          }
        }
      }
      if (style !== '') {
        el.style = style
      }
    }
  }
})
